package cn.b.sky.user.service.model;

import cn.b.sky.common.constants.SystemConstant;
import cn.b.sky.common.model.ImeCommon;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * 用户信息类
 * 
 * @author Admin
 * 
 */
public class UserInfo extends ImeCommon implements UserDetails {

  /** 
  * @Fields serialVersionUID :
  * @creator     :lidapeng
  */
  private static final long serialVersionUID = 1L;

  String siteCode;

  String userCode;

  String username;// 为计算值：userCode@siteCode

  String userText;

  String password;

  Date fromDate;

  Date toDate;

  String fromDateStr;

  String toDateStr;

  Date passwordChangeDate;

  Integer passwordErrorTimes;

  String languageCode = "zh"; //给个默认值

  String timeZoneCode;

  String userTypeECode;

  String userTypeText;// 用户类型描述

  int lockFlag;

  Integer systemFlag;

  String contactName;

  Date birthDate;

  String birthDateStr;

  String telephone;

  String mobile;

  String fax;

  String email;

  String postcode;

  boolean isChecked;

  String address;

  List<UserRole> roleList;

  List<UserOrganization> orgList;

  String javaTimeZoneId;

  String newPassword;

  String wechat;//微信

  String smartWatch;//智能手表

  /**
   * 权限资源 form
   */
  private Collection<GrantedAuthority> authorities;

  /**
   * 按钮权限资源
   */
  private Collection<GrantedAuthority> buttonAuthorities;

  /**
   * 超级管理员账号SA
   */
  public static final String ADMINISTRATOR = "SA";
  
  public String getNewPassword() {
    return newPassword;
  }

  public void setNewPassword(String newPassword) {
    this.newPassword = newPassword;
  }

  public String getJavaTimeZoneId() {
    return javaTimeZoneId;
  }

  public void setJavaTimeZoneId(String javaTimeZoneId) {
    this.javaTimeZoneId = javaTimeZoneId;
  }

  public List<UserRole> getRoleList() {
    return roleList;
  }

  public void setRoleList(List<UserRole> roleList) {
    this.roleList = roleList;
  }

  public List<UserOrganization> getOrgList() {
    return orgList;
  }

  public void setOrgList(List<UserOrganization> orgList) {
    this.orgList = orgList;
  }

  public String getAddress() {
    return address;
  }

  public void setAddress(String address) {
    this.address = address;
  }

  public String getFromDateStr() {
    return fromDateStr;
  }

  public void setFromDateStr(String fromDateStr) {
    this.fromDateStr = fromDateStr;
  }

  public String getToDateStr() {
    return toDateStr;
  }

  public void setToDateStr(String toDateStr) {
    this.toDateStr = toDateStr;
  }

  public String getBirthDateStr() {
    return birthDateStr;
  }

  public void setBirthDateStr(String birthDateStr) {
    this.birthDateStr = birthDateStr;
  }

  public boolean getIsChecked() {
    return isChecked;
  }

  public void setIsChecked(boolean isChecked) {
    this.isChecked = isChecked;
  }

  public String getUserTypeText() {
    return userTypeText;
  }

  public void setUserTypeText(String userTypeText) {
    this.userTypeText = userTypeText;
  }

  @Override
  public String getSiteCode() {
    return siteCode;
  }

  @Override
  public void setSiteCode(String siteCode) {
    this.siteCode = siteCode;
  }

  public String getUserCode() {
    return StringUtils.upperCase(userCode);
  }

  public void setUserCode(String userCode) {
    this.userCode = StringUtils.upperCase(userCode);
  }

  @Override
  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getUserText() {
    return userText;
  }

  public void setUserText(String userText) {
    this.userText = userText;
  }

  @Override
  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public Date getFromDate() {
    return fromDate;
  }

  public void setFromDate(Date fromDate) {
    this.fromDate = fromDate;
  }

  public Date getToDate() {
    return toDate;
  }

  public void setToDate(Date toDate) {
    this.toDate = toDate;
  }

  public Date getPasswordChangeDate() {
    return passwordChangeDate;
  }

  public void setPasswordChangeDate(Date passwordChangeDate) {
    this.passwordChangeDate = passwordChangeDate;
  }

  public Integer getPasswordErrorTimes() {
    return passwordErrorTimes;
  }

  public void setPasswordErrorTimes(Integer passwordErrorTimes) {
    this.passwordErrorTimes = passwordErrorTimes;
  }

  @Override
  public String getLanguageCode() {
    return languageCode;
  }

  @Override
  public void setLanguageCode(String languageCode) {
    this.languageCode = languageCode;
  }

  public String getTimeZoneCode() {
    return timeZoneCode;
  }

  public void setTimeZoneCode(String timeZoneCode) {
    this.timeZoneCode = timeZoneCode;
  }

  public String getUserTypeECode() {
    return userTypeECode;
  }

  public void setUserTypeECode(String userTypeECode) {
    this.userTypeECode = userTypeECode;
  }

  public int getLockFlag() {
    return lockFlag;
  }

  public void setLockFlag(int lockFlag) {
    this.lockFlag = lockFlag;
  }

  public Integer getSystemFlag() {
    return systemFlag;
  }

  public void setSystemFlag(Integer systemFlag) {
    this.systemFlag = systemFlag;
  }

  public String getContactName() {
    return contactName;
  }

  public void setContactName(String contactName) {
    this.contactName = contactName;
  }

  public Date getBirthDate() {
    return birthDate;
  }

  public void setBirthDate(Date birthDate) {
    this.birthDate = birthDate;
  }

  public String getTelephone() {
    return telephone;
  }

  public void setTelephone(String telephone) {
    this.telephone = telephone;
  }

  public String getMobile() {
    return mobile;
  }

  public void setMobile(String mobile) {
    this.mobile = mobile;
  }

  public String getFax() {
    return fax;
  }

  public void setFax(String fax) {
    this.fax = fax;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public String getPostcode() {
    return postcode;
  }

  public void setPostcode(String postcode) {
    this.postcode = postcode;
  }

  @Override
  public Collection<? extends GrantedAuthority> getAuthorities() {

    return this.authorities;
  }

  public void setAuthorities(Collection<GrantedAuthority> authorities) {
    this.authorities = authorities;
  }

  public Collection<GrantedAuthority> getButtonAuthorities() {
    return buttonAuthorities;
  }

  public void setButtonAuthorities(Collection<GrantedAuthority> buttonAuthorities) {
    this.buttonAuthorities = buttonAuthorities;
  }

  @Override
  public boolean isAccountNonExpired() {
    if (this.lockFlag == SystemConstant.COMMON_STATUS_ON) {
      return false;
    }
    return true;
  }

  @Override
  public boolean isAccountNonLocked() {
    if (this.lockFlag == SystemConstant.COMMON_STATUS_ON) {
      return false;
    }
    return true;
  }

  @Override
  public boolean isCredentialsNonExpired() {
    if (this.lockFlag == SystemConstant.COMMON_STATUS_ON) {
      return false;
    }
    return true;
  }

  @Override
  public boolean isEnabled() {
    if (this.lockFlag == SystemConstant.COMMON_STATUS_ON) {
      return false;
    }
    return true;
  }

  public String getWechat() {
    return wechat;
  }

  public void setWechat(String wechat) {
    this.wechat = wechat;
  }

  public String getSmartWatch() {
    return smartWatch;
  }

  public void setSmartWatch(String smartWatch) {
    this.smartWatch = smartWatch;
  }
  
  public boolean isAdministrator() {
    return ADMINISTRATOR.equalsIgnoreCase(this.userCode);
  }

}
